// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const PROTOCOL_CONFIG = {
    MSG_TYPE: {
        INVALID: 0, // 无效
        VERIFY: 1, // 认证
        AUDIO: 2, // 音频数据
        VIDEO: 3, // 视频编码后数据
        CHANNEL: 4, //双向数据通道
        TOUCH: 6, // 触摸数据
        CMD_CONTROL: 7, // 控制指令
        HEART_BEAT: 8, // 心跳数据
        ORIENTATION: 9, // 旋转
        ORIENTATION_TimeStamp: 10, // 旋转与出帧时间
        KEYBOARD_INPUT: 14, // 远程输入法
        KEY_EVENT_EVENT: 15,
        CAMERA: 21, // 摄相头
        MICROPHONE: 22, // 麦克风
        SENSOR: 23, // 传感器
        GpsLocation: 24 // gps
    },
    CAMERA_MESSAGE_TYPE: {
        OPT_CAMERA_GET_PARAM_REQ: 0x1,
        OPT_CAMERA_GET_PARAM_RSP: 0x1001,
        OPT_CAMERA_SET_PARAM_REQ: 0x2,
        OPT_CAMERA_SET_PARAM_RSP: 0x1002,
        OPT_CAMERA_GET_INFO_REQ: 0x3,
        OPT_CAMERA_SET_INFO_RSP: 0x1003,
        OPT_CAMERA_START_PREVIEW_REQ: 0x4,
        OPT_CAMERA_START_PREVIEW_RSP: 0x1004,
        OPT_CAMERA_STOP_PREVIEW_REQ: 0x5,
        OPT_CAMERA_STOP_PREVIEW_RSP: 0x1005,
        OPT_CAMERA_IS_SUPPORT_H264_REQ: 0x6,
        OPT_CAMERA_IS_SUPPORT_H264_RSP: 0x1006,
        OPT_CAMERA_GET_SIZE_REQ: 0x7,
        OPT_CAMERA_GET_SIZE_RSP: 0x1007,
        OPT_CAMERA_FRAME: 0x8,
        OPT_INVALID: 0x9
    },
    MICROPHONE_MESSAGE_TYPE: {
        OPT_MIC_START_RECORD_REQ: 0x1,
        OPT_MIC_STOP_RECOED_REQ: 0x2,
        OPT_MIC_SET_PARAM_REQ: 0x3,
        OPT_MIC_AUDIO_FRAME: 0x10,
        OPT_MIC_START_RECORD_RSP: 0x1001,
        OPT_MIC_STOP_RECOED_RSP: 0x1002,
        OPT_MIC_SET_PARAM_RSP: 0x1003
    },
    SENSOR_MESSAGE_TYPE: {
        OPT_SENDOR_ENABLE_REQ: 0x1,
        OPT_SENSOR_ENABLE_RSP: 0x1001,
        OPT_SENSOR_DISABLE_REQ: 0x2,
        OPT_SENSOR_DISABLE_RSP: 0x1002,
        OPT_SENSOR_DATA: 0x10,
        TYPE_ACCELEROMETER: 0,
        TYPE_GYROSCOPE: 1
    },
    GPS_LOCATION_MESSAGE_TYPE: {
        OPT_LOCATION_OPEN_REQ: 0X0,
        OPT_LOCATION_CLOSE_REQ: 0X1,
        OPT_LOCATION_DATA: 0X2
    },
    CMD_TYPE: {
        VERIFY: '0',
        START: '1',
        STOP: '2',
        RECONNECT: '3',
        PAUSE: '4',
        RESUME: '5',
        REQUEST_I_FRAME: '6',
        SET_MEDIA_CONFIG: '7',
    },
    CMD_RESULT: {
        FAIL: '0',
        SUC: '1'
    },
    CMD_RESP_TYPE: {
        CONNECT_FAILED: 0x0301,
        VERIFY_FAILED: 0x0606,
        START_FAILED: 0x0904,
        PAUSE_TIMEOUT: 0x1000,
        PLAY_TIMEOUT: 0x0E00,
        TOUCH_TIMEOUT: 0x0F00,
        MEDIA_CONFIG_SUCCESS: 0x2100,
        START_SUCCESS: 0x0800,
        RECONNECT_PARAMETER_INVALID: 0x0D01,
        RECONNECT_SERVER_UNREACHABLE: 0x0D02,
        RECONNECT_ENGING_START_ERROR: 0x0D03,
        H265_NOT_SUPPORT: 0x1102,
        VERIFY_SESSION_ID_INVALID: 0x0607,
        INVALID_OPERATION: 0xFFFF,
        PHONE_CONNECTED: 0x2300,
        PHONE_CONNECTED_EXCEED_LIMIT: 0x0302,
    },
    ACTIONS_TYPE: {
        DOWN: 0,
        UP: 1,
        MOVE: 2,
        POINTER_DOWN: 5,
        POINTER_UP: 6
    },
    HEADER_LENGTH: 8,
    ORIENTATION: {
        0: 'PORTRAIT',
        1: 'LANDSCAPE', // 从竖屏逆时针旋转90度
        8: 'REVERSE_LANDSCAPE',
        24: 'LANDSCAPE',
        16: 'REVERSE_PORTRAIT'
    },
    RESOLUTIONS: {
        DISPLAY_480P: {
            width: 480,
            height: 848
        },
        DISPLAY_540P: {
            width: 544,
            height: 960
        },
        DISPLAY_720P: {
            width: 720,
            height: 1280
        },
        DISPLAY_1080P: {
            width: 1080,
            height: 1920
        }
    },
    'UHD': {
        quality: 'best'
    },
    'HD': {
        quality: 'main'
    },
    'SD': {
        quality: 'basic'
    },
    DEFAULT_RESOLUTION: {
        width: 720,
        height: 1280
    },
    KEYBOARD_INPUT_MSG_TYPE: {
        INPUT_EVENT: 0X00,
        HIDE_KEYBOARD_EVENT: 0X01,
        TEXT_UPDATE: 0X02,
        IME_PASTE_TO_SDK: 6,  // PC|移动端 云机到本地
        IME_PASTE_FROM_SDK: 7,  // 移动端 本地到云机
        IME_PASTE_FROM_PC_SDK: 8  // PC端 本地到云机
    },
    KEYBOARD_INPUT_HEADER_LENGTH:3,
    REMOTE_IME: {
        CLOUD_PHONE_KEYBOARD: '0',
        CLIENT_KEYBOARD: '1'
    },
    PHONE_CONNECTION_STATE: {
        1: {
            state: 1,
            message: 'The Phone has been connected by other user.'
        },
        2: {
            state: 2,
            message: 'Connection number exceeds the limit.'
        },
        3: {
            state: 3,
            message: 'Connection to phone failed.'
        },
        4: {
            state: 4,
            message: 'No operations for a long time.'
        },
        5: {
            state: 5,
            message: 'Please log in to the cloud phone again.'
        }
    },
    KEYEVENT_KEYCODE_TYPE: {
        ACTION_DOWN: 0,
        ACTION_UP: 1,
        KEYCODE_HOME: 3,
        KEYCODE_BACK: 4,
        KEYCODE_APP_SWITCH: 187,
    },
    PC_KEY_MAP: {
        8: 67, // 退格
        32: 62, // 空格
        13: 66, // 回车
        27: 4, // ESC
        38: 19, // 上
        40: 20, // 下
        39: 22, // 右
        37: 21, // 左
        20: 115, // 大写锁定
    },
    PC_KEY_PRESS_MAP: {
        // A-Z
        65: 29,
        66: 30,
        67: 31,
        68: 32,
        69: 33,
        70: 34,
        71: 35,
        72: 36,
        73: 37,
        74: 38,
        75: 39,
        76: 40,
        77: 41,
        78: 42,
        79: 43,
        80: 44,
        81: 45,
        82: 46,
        83: 47,
        84: 48,
        85: 49,
        86: 50,
        87: 51,
        88: 52,
        89: 53,
        90: 54,
        
        // a-z 
        97: 29,
        98: 30,
        99: 31,
        100: 32,
        101: 33,
        102: 34,
        103: 35,
        104: 36,
        105: 37,
        106: 38,
        107: 39,
        108: 40,
        109: 41,
        110: 42,
        111: 43,
        112: 44,
        113: 45,
        114: 46,
        115: 47,
        116: 48,
        117: 49,
        118: 50,
        119: 51,
        120: 52,
        121: 53,
        122: 54,

        // 0-9
        48: 7,
        49: 8,
        50: 9,
        51: 10,
        52: 11,
        53: 12,
        54: 13,
        55: 14,
        56: 15,
        57: 16,

        44: 55, // ,
        46: 56, // .
        47: 76, // /
        59: 74, // ;
        39: 75, // ''
        96: 68, // 反引号 
        45: 69, // - 
        61: 70, // =
        91: 71, // [ 
        93: 72, // ] 
        92: 73, // \
        35: 18, // #
        64: 77, // @
        42: 155, // *
        43: 157, // +
        40: 162, // (
        41: 163, // )
    },
    PC_INUPT_MAP: {
        8: 67, // 退格
        13: 66, // 回车
        39: 22, // 右
        37: 21, // 左
    },
    KEYBOARD_TYPE_MAP: {
        PC_INPUT: 1, // 常规键盘输入
        KEYCODE_INPUT: 2 // keycode输入
    }
};

export default PROTOCOL_CONFIG;
